package cn.cdm.dao;

import cn.cdm.domain.MiaoshaOrder;
import cn.cdm.domain.OrderInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

/**
 * 该OrderDao类，包含了订单信息表OrderInfo、秒杀订单表MiaoshaOrder的插入操作
 */
public interface OrderDao {
	
	@Select("select * from miaosha_order where user_id=#{userId} and goods_id=#{goodsId}")
	MiaoshaOrder getMiaoshaOrderByUserIdGoodsId(@Param("userId") long userId, @Param("goodsId") long goodsId);

	// @SelectKey注解，会在插入完成该记录时，立马返回订单表中这条记录的主键id，即返回订单标识
	@Insert("insert into order_info(user_id, goods_id, goods_name, goods_count, goods_price, order_channel, status, create_date)values("
			+ "#{userId}, #{goodsId}, #{goodsName}, #{goodsCount}, #{goodsPrice}, #{orderChannel},#{status},#{createDate} )")
	@SelectKey(keyColumn="id", keyProperty="id", resultType=long.class, before=false, statement="select last_insert_id()")
	long insert(OrderInfo orderInfo);
	
	@Insert("insert into miaosha_order (user_id, goods_id, order_id)values(#{userId}, #{goodsId}, #{orderId})")
	int insertMiaoshaOrder(MiaoshaOrder miaoshaOrder);


	@Delete("delete from order_info")
    void deleteOrders();

	@Delete("delete from miaosha_order")
	void deleteMiaoshaOrders();
}
